package com.xinbochuang.machine.admin.service.impl.macRoom;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import cn.hutool.core.date.DateUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinbochuang.machine.admin.domain.macRoom.ContrastEquCabinet;
import com.xinbochuang.machine.admin.domain.macRoom.ContrastEquipmentDetail;
import com.xinbochuang.machine.admin.domain.macRoom.EquCabinet;
import com.xinbochuang.machine.admin.domain.macRoom.Equipment;
import com.xinbochuang.machine.admin.domain.macRoom.EquipmentDetail;
import com.xinbochuang.machine.admin.dto.ContrastEquCabinetDto;
import com.xinbochuang.machine.admin.dto.EquipmentDetailDto;
import com.xinbochuang.machine.admin.mapper.macRoom.ContrastEquCabinetMapper;
import com.xinbochuang.machine.admin.mapper.macRoom.EquCabinetMapper;
import com.xinbochuang.machine.admin.mapper.macRoom.EquipmentDetailMapper;
import com.xinbochuang.machine.admin.mapper.macRoom.EquipmentMapper;
import com.xinbochuang.machine.admin.service.macRoom.IContrastEquCabinetService;
import com.xinbochuang.machine.common.utils.StringUtils;

/**
 * @author 杜文博
 * @date 2020-09-21
 */
@Service
public class ContrastEquCabinetServiceImpl extends ServiceImpl<ContrastEquCabinetMapper, ContrastEquCabinet> implements IContrastEquCabinetService {

    @Autowired
    ContrastEquCabinetMapper contrastEquCabinetMapper;

    @Autowired
    EquCabinetMapper equCabinetMapper;

    @Autowired
    EquipmentDetailMapper equipmentDetailMapper;

    @Autowired
    EquipmentMapper equipmentMapper;

    @Override
    public List<ContrastEquCabinetDto> selectContrasCabinetList(ContrastEquCabinetDto contrastEquCabinetDto) {
        String pageSize = contrastEquCabinetDto.getPageSize().toString();
        String pageNum = contrastEquCabinetDto.getPageNum().toString();
        String macId = contrastEquCabinetDto.getMacId();
        String planId = contrastEquCabinetDto.getPlanId();
        return contrastEquCabinetMapper.selectContrasCabinetList(macId, planId, pageNum, pageSize);
    }

    @Override
    public Integer selectContrasCabinetCount(ContrastEquCabinetDto contrastEquCabinetDto) {
        String pageSize = contrastEquCabinetDto.getPageSize().toString();
        String pageNum = contrastEquCabinetDto.getPageNum().toString();
        String macId = contrastEquCabinetDto.getMacId();
        String planId = contrastEquCabinetDto.getPlanId();
        return contrastEquCabinetMapper.selectContrasCabinetCount(macId, planId, pageNum, pageSize);
    }

    @Override
    public Integer updatEquCabinet(Integer checkKey, String contrasCabinetIds,String planId) {
        //checkKey为0不修改原始数据，1单修机柜，2全量修机柜,3单修机柜下所有设备
        String[] cabinetIdList = contrasCabinetIds.split(",", -1);
        ContrastEquCabinet contrastEquCabinet = new ContrastEquCabinet();
        QueryWrapper<EquCabinet> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(EquCabinet::getDeleteFlag, 0);
        Integer result = null;
        String cabinetId = null;
        EquCabinet equCabinet = new EquCabinet();
        List<EquipmentDetailDto> equDetailDtoList = new ArrayList<>();
        List<ContrastEquipmentDetail> contrastEquipmentDetailList = new ArrayList<>();
        EquipmentDetail equipmentDetail = new EquipmentDetail();
        Equipment equipment = new Equipment();
//        //审核数据，若传入后端的机柜Id不存在于原始表则逻辑删除该机柜及旗下所有数据
//        if (checkKey != 0 && StringUtils.isNotEmpty(macId)) {
//            List<String> oldCabinets = new ArrayList<>();
//            //根据macId获取原表cabientId
//            oldCabinets = equCabinetMapper.findEquCabinetByMacId(macId);
//            //对比原表cabientId与核验表cabientId取交集之外的集合
//            Collection<String> col = CollectionUtils.union(Arrays.asList(cabinetIdList), oldCabinets);
//            col = CollectionUtils.disjunction(Arrays.asList(cabinetIdList), oldCabinets);
//            //将差集中的机柜原始数据及其下设备做逻辑删除
//            for (String str : col) {
//                EquCabinet surplusCabinet = new EquCabinet();
//                Equipment surplusEquipment = new Equipment();
//                EquipmentDetail surplusEquDetail = new EquipmentDetail();
//                surplusCabinet = equCabinetMapper.selectById(str);
//                surplusCabinet.setDeleteFlag(1);
//                //删除机柜数据
//                equCabinetMapper.updateById(surplusCabinet);
//                QueryWrapper<Equipment> warrperEqu = new QueryWrapper<>();
//                QueryWrapper<EquipmentDetail> warrperEquDetail = new QueryWrapper<>();
//                warrperEqu.lambda().eq(Equipment::getCabinetId, str);
////                surplusEquipment = equipmentMapper.selectOne(warrperEqu);
////                if (surplusEquipment != null) {
////                    surplusEquipment.setDeleteFlag(1);
////                    //删除机柜下设备数据
////                    equipmentMapper.updateById(surplusEquipment);
////                }
//                surplusEquipment.setDeleteFlag(1);
//                equipmentMapper.update(surplusEquipment,warrperEqu);
//                warrperEquDetail.lambda().eq(EquipmentDetail::getCabinetId, str);
//                surplusEquDetail.setDeleteFlag(1);
//                //删除机柜下资产数据
//                equipmentDetailMapper.update(surplusEquDetail, warrperEquDetail);
//            }
//        }
        if(checkKey!=0){
            //根据机柜Id查询机柜核查表内optType 若为2则为删除操作，则删除原始数据
            for (int i =0;i<cabinetIdList.length;i++){
                QueryWrapper<ContrastEquCabinet> warrperContrastEquCabinet = new QueryWrapper<>();
                warrperContrastEquCabinet.lambda().eq(ContrastEquCabinet::getCabinetId,cabinetIdList[i]).eq(ContrastEquCabinet::getPlanId,planId);
                contrastEquCabinet = contrastEquCabinetMapper.selectOne(warrperContrastEquCabinet);
                String optType = contrastEquCabinet.getOptType();
                if(optType.equals("2")){
                    EquCabinet equCabinet1 = new EquCabinet();
                    equCabinet1 = equCabinetMapper.selectById(cabinetIdList[i]);
                    //删除机柜原表数据
                    equCabinet1.setDeleteFlag(1);
                    equCabinetMapper.updateById(equCabinet1);
                    QueryWrapper<Equipment> warrperEqu = new QueryWrapper<>();
                    QueryWrapper<EquipmentDetail> warrperEquDetail = new QueryWrapper<>();
                    Equipment surplusEquipment = new Equipment();
                    EquipmentDetail surplusEquDetail = new EquipmentDetail();
                    warrperEqu.lambda().eq(Equipment::getCabinetId,cabinetIdList[i]);
                    surplusEquipment = equipmentMapper.selectOne(warrperEqu);
                    surplusEquipment.setDeleteFlag(1);
                    //删除机柜下设备数据
                    equipmentMapper.updateById(surplusEquipment);
                    warrperEquDetail.lambda().eq(EquipmentDetail::getCabinetId,cabinetIdList[i]);
                    surplusEquDetail = equipmentDetailMapper.selectOne(warrperEquDetail);
                    surplusEquDetail.setDeleteFlag(1);
                    //删除机柜下资产数据
                    equipmentDetailMapper.updateById(surplusEquDetail);
                }
            }
        }
        if (checkKey == 0) {
            for (int i = 0; i < cabinetIdList.length; i++) {
                //根据机柜Id 查询核查表内机柜详情
                QueryWrapper<ContrastEquCabinet> contrastEquCabinetQueryWrapper = new QueryWrapper<>();
                contrastEquCabinetQueryWrapper.lambda().eq(ContrastEquCabinet::getCabinetId,cabinetIdList[i]).eq(ContrastEquCabinet::getPlanId,planId);
                List<ContrastEquCabinet> contrastEquCabinets = contrastEquCabinetMapper.selectList(contrastEquCabinetQueryWrapper);
                for(ContrastEquCabinet contrastEquCabinet1:contrastEquCabinets){
                    if (contrastEquCabinet1 != null) {
                        contrastEquCabinet1.setCheckState(1);
                        result = contrastEquCabinetMapper.updateById(contrastEquCabinet1);
                    }
                }
            }
        } else if (checkKey == 1) {
            for (int i = 0; i < cabinetIdList.length; i++) {

                QueryWrapper<ContrastEquCabinet> contrastEquCabinetQueryWrapper = new QueryWrapper<>();
                contrastEquCabinetQueryWrapper.lambda().eq(ContrastEquCabinet::getCabinetId,cabinetIdList[i]).eq(ContrastEquCabinet::getPlanId,planId);
                List<ContrastEquCabinet> contrastEquCabinets = contrastEquCabinetMapper.selectList(contrastEquCabinetQueryWrapper);
                if(!contrastEquCabinets.isEmpty()){
                    contrastEquCabinet=contrastEquCabinets.get(0);
                }
//                contrastEquCabinet = contrastEquCabinetMapper.selectById(cabinetIdList[i]);
                equCabinet = equCabinetMapper.selectById(cabinetIdList[i]);
                //若前端传入设备Id查询原始表为空则在原始表插入数据
                if (equCabinet == null) {
                    contrastEquCabinet.setCheckState(1);
                    //修改审核状态
                    result = contrastEquCabinetMapper.updateById(contrastEquCabinet);
                    equCabinet.setMacId(contrastEquCabinet.getMacId());
                    equCabinet.setCabinetName(contrastEquCabinet.getCabinetName());
                    equCabinet.setEnergyName(contrastEquCabinet.getEnergyName());
                    equCabinet.setUlocationQuantity(contrastEquCabinet.getUlocationQuantity());
                    equCabinet.setUpdateTime(DateUtil.now());
                    equCabinet.setCreateTime(DateUtil.now());
                    equCabinet.setUuid(contrastEquCabinet.getUuid());
                    equCabinet.setDeleteFlag(0);
                    equCabinetMapper.insert(equCabinet);
                } else {
                    if (contrastEquCabinet != null) {
                        contrastEquCabinet.setCheckState(1);
                        result = contrastEquCabinetMapper.updateById(contrastEquCabinet);
                        cabinetId = contrastEquCabinet.getCabinetId();
                        equCabinet = equCabinetMapper.selectById(cabinetId);
                        equCabinet.setMacId(contrastEquCabinet.getMacId());
                        equCabinet.setCabinetName(contrastEquCabinet.getCabinetName());
                        equCabinet.setEnergyName(contrastEquCabinet.getEnergyName());
                        equCabinet.setUlocationQuantity(contrastEquCabinet.getUlocationQuantity());
                        equCabinet.setUpdateTime(DateUtil.now());
                        equCabinetMapper.updateById(equCabinet);
                    }
                }
            }
        } else if (checkKey == 2) {
            contrastEquCabinet.setCheckState(2);
            //修改审核状态
            result = contrastEquCabinetMapper.updateById(contrastEquCabinet);
            for (int i = 0; i < cabinetIdList.length; i++) {
                QueryWrapper<ContrastEquCabinet> contrastEquCabinetQueryWrapper = new QueryWrapper<>();
                contrastEquCabinetQueryWrapper.lambda().eq(ContrastEquCabinet::getCabinetId,cabinetIdList[i]).eq(ContrastEquCabinet::getPlanId,planId);
                List<ContrastEquCabinet> contrastEquCabinets = contrastEquCabinetMapper.selectList(contrastEquCabinetQueryWrapper);
                if(!contrastEquCabinets.isEmpty()){
                    contrastEquCabinet=contrastEquCabinets.get(0);
                }

                equCabinet = equCabinetMapper.selectById(cabinetIdList[i]);
                //若原始表机柜数据为空则将机柜及旗下设备全部插入原始表
                if (equCabinet == null) {
                    cabinetId = contrastEquCabinet.getCabinetId();
                    equCabinet = equCabinetMapper.selectById(cabinetId);
                    equCabinet.setMacId(contrastEquCabinet.getMacId());
                    equCabinet.setCabinetName(contrastEquCabinet.getCabinetName());
                    equCabinet.setEnergyName(contrastEquCabinet.getEnergyName());
                    equCabinet.setUlocationQuantity(contrastEquCabinet.getUlocationQuantity());
                    equCabinet.setUpdateTime(DateUtil.now());
                    equCabinet.setCreateTime(DateUtil.now());
                    equCabinet.setUuid(contrastEquCabinet.getUuid());
                    equCabinet.setDeleteFlag(0);
                    equCabinetMapper.insert(equCabinet);
                    contrastEquipmentDetailList = contrastEquCabinetMapper.selectEquDetailByCabinetId(cabinetId);
                    if (contrastEquipmentDetailList.size() > 0) {
                        for (int j = 0; j < contrastEquipmentDetailList.size(); j++) {
                            equipment.setCabinetId(contrastEquipmentDetailList.get(j).getCabinetId());
                            equipment.setEquHeight(contrastEquipmentDetailList.get(j).getEquHeight());
                            equipment.setEquName(contrastEquipmentDetailList.get(j).getEquName());
                            equipment.setEquState(contrastEquipmentDetailList.get(j).getEquState());
                            equipment.setUpdateTime(DateUtil.now());
                            equipment.setCreateTime(DateUtil.now());
                            equipment.setDeleteFlag(0);
                            if(StringUtils.isNotBlank(equipment.getEquHeight())&&equipment.getEquHeight().contains("-")){
                                String[] he=equipment.getEquHeight().split("-");
                                equipment.setHeight(Integer.valueOf(he[1])-Integer.valueOf(he[0])+1);
                            }else{
                                equipment.setHeight(0);
                            }
                            equipment.setUuid(contrastEquipmentDetailList.get(j).getUuid());
                            //插入原始设备表
                            equipmentMapper.insert(equipment);
                            equipmentDetail.setCabinetName(contrastEquipmentDetailList.get(j).getCabinetName());
                            equipmentDetail.setAssetsBigType(contrastEquipmentDetailList.get(j).getAssetsBigType());
                            equipmentDetail.setAssetsSmallType(contrastEquipmentDetailList.get(j).getAssetsSmallType());
                            equipmentDetail.setAssetsNumber(contrastEquipmentDetailList.get(j).getAssetsNumber());
                            equipmentDetail.setUfloorNum(contrastEquipmentDetailList.get(j).getUfloorNum());
                            equipmentDetail.setCabinetId(contrastEquipmentDetailList.get(j).getCabinetId());
                            equipmentDetail.setEquId(contrastEquipmentDetailList.get(j).getEquId());
                            equipmentDetail.setAssetsState(contrastEquipmentDetailList.get(j).getAssetsState());
                            equipmentDetail.setDepartment(contrastEquipmentDetailList.get(j).getDepartment());
                            equipmentDetail.setMacRoomName(contrastEquipmentDetailList.get(j).getMacRoomName());
                            equipmentDetail.setModelType(contrastEquipmentDetailList.get(j).getModelType());
                            equipmentDetail.setOffice(contrastEquipmentDetailList.get(j).getOffice());
                            equipmentDetail.setOpenDate(contrastEquipmentDetailList.get(j).getOpenDate());
                            equipmentDetail.setOwnerSystem(contrastEquipmentDetailList.get(j).getOwnerSystem());
                            equipmentDetail.setPrincipal(contrastEquipmentDetailList.get(j).getPrincipal());
                            equipmentDetail.setUpdateTime(DateUtil.now());
                            equipmentDetail.setCreateTime(DateUtil.now());
                            equipmentDetail.setDeleteFlag(0);
                            equipmentDetail.setUuid(contrastEquipmentDetailList.get(j).getUuid());
                            //插入原始资产列表
                            equipmentDetailMapper.insert(equipmentDetail);
                        }
                    }
                }
                //机柜Id不为空则覆盖原始表数据及旗下所有设备
                else {
                    if (contrastEquCabinet != null) {
                        cabinetId = contrastEquCabinet.getCabinetId();
                        equCabinet = equCabinetMapper.selectById(cabinetId);
                        equCabinet.setMacId(contrastEquCabinet.getMacId());
                        equCabinet.setCabinetName(contrastEquCabinet.getCabinetName());
                        equCabinet.setEnergyName(contrastEquCabinet.getEnergyName());
                        equCabinet.setUlocationQuantity(contrastEquCabinet.getUlocationQuantity());
                        equCabinet.setUpdateTime(DateUtil.now());
                        equCabinetMapper.updateById(equCabinet);
                        equDetailDtoList = contrastEquCabinetMapper.findEquDetailByCabinetId(cabinetId);
                        if (equDetailDtoList.size() > 0) {
                            for (int j = 0; j < equDetailDtoList.size(); j++) {
                                if(StringUtils.isNotBlank(equDetailDtoList.get(j).getEquId())){
                                    equipment = equipmentMapper.selectById(equDetailDtoList.get(j).getEquId());
                                    if (equipment != null) {
                                        equipment.setCabinetId(equDetailDtoList.get(j).getCabinetId());
                                        equipment.setEquHeight(equDetailDtoList.get(j).getEquHeight());
                                        equipment.setEquName(equDetailDtoList.get(j).getEquName());
                                        equipment.setEquState(equDetailDtoList.get(j).getEquState());
                                        equipment.setUpdateTime(DateUtil.now());
                                        if(StringUtils.isNotBlank(equipment.getEquHeight())&&equipment.getEquHeight().contains("-")){
                                            String[] he=equipment.getEquHeight().split("-");
                                            equipment.setHeight(Integer.valueOf(he[1])-Integer.valueOf(he[0])+1);
                                        }else{
                                            equipment.setHeight(0);
                                        }
                                        equipmentMapper.updateById(equipment);
                                    }
                                }
                                if(StringUtils.isNotBlank(equDetailDtoList.get(j).getUuid())){
                                    equipmentDetail = equipmentDetailMapper.selectById(equDetailDtoList.get(j).getUuid());
                                    if (equipmentDetail != null) {
                                        equipmentDetail.setCabinetName(equDetailDtoList.get(j).getCabinetName());
                                        equipmentDetail.setAssetsBigType(equDetailDtoList.get(j).getAssetsBigType());
                                        equipmentDetail.setAssetsSmallType(equDetailDtoList.get(j).getAssetsSmallType());
                                        equipmentDetail.setAssetsNumber(equDetailDtoList.get(j).getAssetsNumber());
                                        equipmentDetail.setUfloorNum(equDetailDtoList.get(j).getUfloorNum());
                                        equipmentDetail.setCabinetId(equDetailDtoList.get(j).getCabinetId());
                                        equipmentDetail.setEquId(equDetailDtoList.get(j).getEquId());
                                        equipmentDetail.setAssetsState(equDetailDtoList.get(j).getAssetsState());
                                        equipmentDetail.setDepartment(equDetailDtoList.get(j).getDepartment());
                                        equipmentDetail.setMacRoomName(equDetailDtoList.get(j).getMacRoomName());
                                        equipmentDetail.setModelType(equDetailDtoList.get(j).getModelType());
                                        equipmentDetail.setOffice(equDetailDtoList.get(j).getOffice());
                                        equipmentDetail.setOpenDate(equDetailDtoList.get(j).getOpenDate());
                                        equipmentDetail.setOwnerSystem(equDetailDtoList.get(j).getOwnerSystem());
                                        equipmentDetail.setPrincipal(equDetailDtoList.get(j).getPrincipal());
                                        equipmentDetail.setUpdateTime(DateUtil.now());
                                        equipmentDetailMapper.updateById(equipmentDetail);
                                    }
                                }

                            }
                        }
                    }
                }
            }
        } else if (checkKey == 3) {
            for (int i = 0; i < cabinetIdList.length; i++) {
                QueryWrapper<ContrastEquCabinet> contrastEquCabinetQueryWrapper = new QueryWrapper<>();
                contrastEquCabinetQueryWrapper.lambda().eq(ContrastEquCabinet::getCabinetId,cabinetIdList[i]).eq(ContrastEquCabinet::getPlanId,planId);
                List<ContrastEquCabinet> contrastEquCabinets = contrastEquCabinetMapper.selectList(contrastEquCabinetQueryWrapper);
                if(!contrastEquCabinets.isEmpty()){
                    contrastEquCabinet=contrastEquCabinets.get(0);
                }
                equCabinet = equCabinetMapper.selectById(cabinetIdList[i]);
                contrastEquCabinet.setCheckState(2);
                //修改审核状态
                result = contrastEquCabinetMapper.updateById(contrastEquCabinet);
                //若机柜数据为空则做新增
                if (equCabinet == null) {
                    if (contrastEquCabinet != null) {
                        cabinetId = contrastEquCabinet.getCabinetId();
                        contrastEquipmentDetailList = contrastEquCabinetMapper.selectEquDetailByCabinetId(cabinetId);
                        if (contrastEquipmentDetailList.size() > 0) {
                            for (int j = 0; j < contrastEquipmentDetailList.size(); j++) {
                                equipment.setCabinetId(contrastEquipmentDetailList.get(j).getCabinetId());
                                equipment.setEquHeight(contrastEquipmentDetailList.get(j).getEquHeight());
                                equipment.setEquName(contrastEquipmentDetailList.get(j).getEquName());
                                equipment.setEquState(contrastEquipmentDetailList.get(j).getEquState());
                                equipment.setUpdateTime(DateUtil.now());
                                equipment.setCreateTime(DateUtil.now());
                                equipment.setDeleteFlag(0);
                                if(StringUtils.isNotBlank(equipment.getEquHeight())&&equipment.getEquHeight().contains("-")){
                                    String[] he=equipment.getEquHeight().split("-");
                                    equipment.setHeight(Integer.valueOf(he[1])-Integer.valueOf(he[0])+1);
                                }else{
                                    equipment.setHeight(0);
                                }
                                equipment.setUuid(contrastEquipmentDetailList.get(j).getUuid());
                                equipmentMapper.insert(equipment);
                                equipmentDetail.setCabinetName(contrastEquipmentDetailList.get(j).getCabinetName());
                                equipmentDetail.setAssetsBigType(contrastEquipmentDetailList.get(j).getAssetsBigType());
                                equipmentDetail.setAssetsSmallType(contrastEquipmentDetailList.get(j).getAssetsSmallType());
                                equipmentDetail.setAssetsNumber(contrastEquipmentDetailList.get(j).getAssetsNumber());
                                equipmentDetail.setUfloorNum(contrastEquipmentDetailList.get(j).getUfloorNum());
                                equipmentDetail.setCabinetId(contrastEquipmentDetailList.get(j).getCabinetId());
                                equipmentDetail.setEquId(contrastEquipmentDetailList.get(j).getEquId());
                                equipmentDetail.setAssetsState(contrastEquipmentDetailList.get(j).getAssetsState());
                                equipmentDetail.setDepartment(contrastEquipmentDetailList.get(j).getDepartment());
                                equipmentDetail.setMacRoomName(contrastEquipmentDetailList.get(j).getMacRoomName());
                                equipmentDetail.setModelType(contrastEquipmentDetailList.get(j).getModelType());
                                equipmentDetail.setOffice(contrastEquipmentDetailList.get(j).getOffice());
                                equipmentDetail.setOpenDate(contrastEquipmentDetailList.get(j).getOpenDate());
                                equipmentDetail.setOwnerSystem(contrastEquipmentDetailList.get(j).getOwnerSystem());
                                equipmentDetail.setPrincipal(contrastEquipmentDetailList.get(j).getPrincipal());
                                equipmentDetail.setUpdateTime(DateUtil.now());
                                equipmentDetail.setUuid(contrastEquipmentDetailList.get(j).getUuid());
                                equipmentDetail.setCreateTime(DateUtil.now());
                                equipmentDetail.setDeleteFlag(0);
                                equipmentDetailMapper.insert(equipmentDetail);
                            }
                        }
                    }
                } else {
                    if (contrastEquCabinet != null) {
                        cabinetId = contrastEquCabinet.getCabinetId();
                        equDetailDtoList = contrastEquCabinetMapper.findEquDetailByCabinetId(cabinetId);
                        if (equDetailDtoList.size() > 0) {
                            for (int j = 0; j < equDetailDtoList.size(); j++) {
                                //查询设备表
                                if(StringUtils.isNotBlank(equDetailDtoList.get(j).getEquUid())){
                                    equipment = equipmentMapper.selectById(equDetailDtoList.get(j).getEquUid());
                                    //查询资产表
                                    if (equipment != null) {
                                        equipment.setCabinetId(equDetailDtoList.get(j).getCabinetId());
                                        equipment.setEquHeight(equDetailDtoList.get(j).getEquHeight());
                                        equipment.setEquName(equDetailDtoList.get(j).getEquName());
                                        equipment.setEquState(equDetailDtoList.get(j).getEquState());
                                        equipment.setUpdateTime(DateUtil.now());
                                        if(StringUtils.isNotBlank(equipment.getEquHeight())&&equipment.getEquHeight().contains("-")){
                                            String[] he=equipment.getEquHeight().split("-");
                                            equipment.setHeight(Integer.valueOf(he[1])-Integer.valueOf(he[0])+1);
                                        }else{
                                            equipment.setHeight(0);
                                        }
                                        equipmentMapper.updateById(equipment);
                                    }
                                }
                                if(StringUtils.isNotBlank(equDetailDtoList.get(j).getUuid())){
                                    equipmentDetail = equipmentDetailMapper.selectById(equDetailDtoList.get(j).getUuid());
                                    if (equipmentDetail != null) {
                                        equipmentDetail.setCabinetName(equDetailDtoList.get(j).getCabinetName());
                                        equipmentDetail.setAssetsBigType(equDetailDtoList.get(j).getAssetsBigType());
                                        equipmentDetail.setAssetsSmallType(equDetailDtoList.get(j).getAssetsSmallType());
                                        equipmentDetail.setAssetsNumber(equDetailDtoList.get(j).getAssetsNumber());
                                        equipmentDetail.setUfloorNum(equDetailDtoList.get(j).getUfloorNum());
                                        equipmentDetail.setCabinetId(equDetailDtoList.get(j).getCabinetId());
                                        equipmentDetail.setEquId(equDetailDtoList.get(j).getEquId());
                                        equipmentDetail.setAssetsState(equDetailDtoList.get(j).getAssetsState());
                                        equipmentDetail.setDepartment(equDetailDtoList.get(j).getDepartment());
                                        equipmentDetail.setMacRoomName(equDetailDtoList.get(j).getMacRoomName());
                                        equipmentDetail.setModelType(equDetailDtoList.get(j).getModelType());
                                        equipmentDetail.setOffice(equDetailDtoList.get(j).getOffice());
                                        equipmentDetail.setOpenDate(equDetailDtoList.get(j).getOpenDate());
                                        equipmentDetail.setOwnerSystem(equDetailDtoList.get(j).getOwnerSystem());
                                        equipmentDetail.setPrincipal(equDetailDtoList.get(j).getPrincipal());
                                        equipmentDetail.setUpdateTime(DateUtil.now());
                                        equipmentDetailMapper.updateById(equipmentDetail);
                                    }
                                }

                            }
                        }
                    }
                }
            }
        }
        return result;
    }
}
